//
//  ExamineProprietorPositionMainView.swift
//  SmartHousekeeper
//
//  Created by 张磊 on 2020/2/20.
//  Copyright © 2020 LS. All rights reserved.
//

import UIKit
//核验业主身份 主
class ExamineProprietorPositionMainView: UIView {
    
    typealias ExamineProprietorPositionViewFinshBlock = ()->()
    public var finshBlock : ExamineProprietorPositionViewFinshBlock? = nil
       
    
    //1 身份信息
    lazy var oneImg : UIImageView = {
        let value = UIImageView(image: UIImage(named: "icon_one_l"))
        return value
    }()
    lazy var positionLable : UILabel = {
        let value = UILabel(textColor: RGBColor(r: 62, g: 134, b: 230, a: 1), textFont: UIFont.systemFont(ofSize: Adapter(13)))
        value.text = "身份信息"
        return value
    }()
    lazy var positionView : ExamineProprietorPositionView = {
        let value = ExamineProprietorPositionView()
        return value
    }()
    
    //2 房产证信息
    lazy var twoImg : UIImageView = {
        let value = UIImageView(image: UIImage(named: "icon_two_h"))
        return value
    }()
    lazy var houseLable : UILabel = {
        let value = UILabel(textColor: RGBColor(r: 116, g: 116, b: 116, a: 1), textFont: UIFont.systemFont(ofSize: Adapter(13)))
        value.text = "房产证信息"
        return value
    }()
    lazy var houseView : ExamineProprietorPositionHouseView = {
        let value = ExamineProprietorPositionHouseView()
        return value
    }()
    
    //3 联网信息
    lazy var thereImg : UIImageView = {
        let value = UIImageView(image: UIImage(named: "icon_there_h"))
        return value
    }()
    lazy var internetLable : UILabel = {
        let value = UILabel(textColor: RGBColor(r: 116, g: 116, b: 116, a: 1), textFont: UIFont.systemFont(ofSize: Adapter(13)))
        value.text = "联网信息"
        return value
    }()
    lazy var internetView : ExamineProprietorPositionInternetView = {
        let value = ExamineProprietorPositionInternetView()
        return value
    }()
    
    lazy var scrollView : UIScrollView = {
        let value = UIScrollView()
        value.delegate = self as? UIScrollViewDelegate
        value.showsHorizontalScrollIndicator = false
        value.showsVerticalScrollIndicator = false
        value.isPagingEnabled = true;
        value.isScrollEnabled = false
        return value
    }()
    
    
    required init?(coder: NSCoder) {
        super .init(coder: coder)
    }
    override init(frame: CGRect) {
        super .init(frame: frame)
        setUI()
    }
    private func setUI(){
        
        let title = UILabel(textColor: RGBColor(r: 185, g: 160, b: 130, a: 1), textFont: UIFont.boldSystemFont(ofSize: Adapter(22)))
        title.text = "核验业主身份"
        self.addSubview(title)
        title.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(20)
            make.top.equalToSuperview().offset(15)
            make.height.equalTo(Adapter(24))
        }
        
        self.addSubview(oneImg)
        oneImg.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(Adapter(50));
            make.top.equalTo(title.snp.bottom).offset(Adapter(15))
            make.size.equalTo(CGSize(width: Adapter(20), height: Adapter(20)))
        }
        
        self.addSubview(positionLable)
        positionLable.snp.makeConstraints { (make) in
            make.centerX.equalTo(oneImg);
            make.top.equalTo(oneImg.snp.bottom).offset(Adapter(5))
            make.height.equalTo(Adapter(15))
        }
        
        
        self.addSubview(twoImg)
        twoImg.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview();
            make.centerY.equalTo(oneImg)
            make.size.equalTo(CGSize(width: Adapter(20), height: Adapter(20)))
        }
        
        self.addSubview(houseLable)
        houseLable.snp.makeConstraints { (make) in
            make.centerX.equalTo(twoImg);
            make.centerY.equalTo(positionLable)
            make.height.equalTo(Adapter(15))
        }
        
        
        let imgLine12 = UIImageView(image: UIImage(named: ""))
        imgLine12.backgroundColor = RGBColor(r: 212, g: 228, b: 249, a: 1)
        self.addSubview(imgLine12)
        imgLine12.snp.makeConstraints { (make) in
            make.centerY.equalTo(oneImg);
            make.left.equalTo(oneImg.snp.right)
            make.height.equalTo(1)
            make.right.equalTo(twoImg.snp.left)
        }
        
        
        self.addSubview(thereImg)
        thereImg.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(-Adapter(50));
            make.centerY.equalTo(oneImg)
            make.size.equalTo(CGSize(width: Adapter(20), height: Adapter(20)))
        }
        
        self.addSubview(internetLable)
        internetLable.snp.makeConstraints { (make) in
            make.centerX.equalTo(thereImg);
            make.centerY.equalTo(positionLable)
            make.height.equalTo(Adapter(15))
        }
        let imgLine23 = UIImageView(image: UIImage(named: ""))
        imgLine23.backgroundColor = RGBColor(r: 212, g: 228, b: 249, a: 1)
        self.addSubview(imgLine23)
        imgLine23.snp.makeConstraints { (make) in
            make.centerY.equalTo(oneImg);
            make.left.equalTo(twoImg.snp.right)
            make.height.equalTo(1)
            make.right.equalTo(thereImg.snp.left)
        }
        
        let line = UIView()
        line.backgroundColor = RGBColor(r: 214, g: 214, b: 214, a: 1)
        self.addSubview(line)
        line.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(Adapter(115))
            make.left.equalToSuperview().offset(Adapter(10));
            make.right.equalToSuperview().offset(Adapter(-10));
            make.height.equalTo(0.8)
        }
        
        
        let top = UIDevice.isX() ? 44.0 : 20.0;
        let height : Float =  Float(ScreenHeight - CGFloat(top) - 44 - Adapter(60) - Adapter(115))
        scrollView.contentSize = CGSize(width: (ScreenWidth - Adapter(30)) * 3, height: CGFloat(100))
        self.addSubview(scrollView)
        scrollView.snp.makeConstraints { (make) in
            make.left.equalToSuperview()
            make.top.equalTo(line.snp.bottom);
            make.size.equalTo(CGSize(width: (ScreenWidth - Adapter(30)), height: CGFloat(height)))
        }
        
        let views = [positionView,houseView,internetView]
        scrollView.addSubviews(views)
        views.enumerated().forEach{ (idx, view) in
            view.snp.makeConstraints { (make) in
                make.height.equalTo(height)
                make.width.equalTo((ScreenWidth - Adapter(30)))
                make.top.equalToSuperview()
                make.left.equalToSuperview().offset(idx * Int(ScreenWidth - Adapter(30)))
            }
        }
    
        
        positionView.nextBlock = {
            self.scrollView.setContentOffset(CGPoint(x: (ScreenWidth - Adapter(30)), y: 0), animated: true)
            self.changeHeader(1)
        }
        houseView.nextHouseBlock = {
            self.scrollView.setContentOffset(CGPoint(x: (ScreenWidth - Adapter(30)) * 2, y: 0), animated: true)
            self.changeHeader(2)
        }
        internetView.nextInternetBlock = {
            print("完成")
            if self.finshBlock != nil {
                self.finshBlock!()
            }
        }
    }
    func changeHeader(_ index:Int) {
        switch index {
        case 1:
            oneImg.image = UIImage(named: "icon_one_h")
            positionLable.textColor = RGBColor(r: 116, g: 116, b: 116, a: 1)
            twoImg.image = UIImage(named: "icon_two_l")
            houseLable.textColor = RGBColor(r: 62, g: 134, b: 230, a: 1)
            thereImg.image = UIImage(named: "icon_there_h")
            internetLable.textColor = RGBColor(r: 116, g: 116, b: 116, a: 1)
            
            break
        case 2:
            oneImg.image = UIImage(named: "icon_one_h")
            positionLable.textColor = RGBColor(r: 116, g: 116, b: 116, a: 1)
            
            twoImg.image = UIImage(named: "icon_two_h")
            houseLable.textColor = RGBColor(r: 116, g: 116, b: 116, a: 1)
            
            thereImg.image = UIImage(named: "icon_there_l")
            internetLable.textColor = RGBColor(r: 62, g: 134, b: 230, a: 1)
            
            break
            
        default:
            break
        }
    }
}
